﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KPIS.GERP.GBMS.BLL;
using KPIS.GERP.GBMS.IBLL;
using KPIS.GERP.GBMS.MODEL;
using Telerik.Web.UI;

namespace KPIS.GERP.GBMS.APP_UI
{
    public partial class ExpenseCombo : System.Web.UI.UserControl
    {
        public RadComboBox ctrChild;
        public event RadTreeViewEventHandler TreeView_OnClick;
        private IExpenseBLL exp = new ExpenseBLL();
        private RadTreeView tView;

        protected void Page_PreRender(object sender, EventArgs e)
        {
        }

        public void LoadExpenseComboBox(bool isRootNode)
        {
            LoadExpenseComboBox("", "", "", "", "", "", isRootNode);
        }

        public void LoadExpenseComboBox(string seq, string code, string name, string descr, string parent, string expGrp, bool isRootNode)
        {
            cbExpense1.Items[0].Value = "root";

            tView = (RadTreeView)cbExpense1.Items[0].FindControl("tExpense");
            IList<TreeViewInfo> tvInfo = new List<TreeViewInfo>();

            tView.DataSource = exp.TreeView(tvInfo, isRootNode, expGrp);

            //cbParent.DataSource = exp.Search(seq, code, name, descr, "", expType, parent, expGrp);
            tView.DataBind();

            //cbParent.Items.Insert(0, new RadComboBoxItem("- เลือกค่าใช้จ่าย -"));
        }

        protected void cbExpense_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (cbExpense1.SelectedIndex > 0)
            {
                cbExpense1.Items[0].Value = tView.SelectedValue;

                if (ctrChild != null)
                {
                    //ctrChild.DataSource = exp.Search(0, "", "", "", 0, val);
                    //ctrChild.DataBind();

                    //ctrChild.Items.Insert(0, new RadComboBoxItem("- เลือกค่าใช้จ่าย -"));
                }
            }
            else
                if (ctrChild != null)
                    ctrChild.Items.Clear();
        }
    }
}